package com.aaron.test;

import cn.hutool.crypto.digest.MD5;

import java.security.MessageDigest;

/**
 * @author liurong
 * @date 2021/11/8 9:55
 * @version:
 */
public class SignUtil {

//    public String genSignature(DHSecondAuthReq authReq){
//        MD5 md5 = MD5.create();
//        md5.digestHex16()
//        String signature = MD5Utils.encrypt(password, encryptType);
//        signature = MD5Utils.encrypt(userName + signature, encryptType);
//        signature = MD5Utils.encrypt(signature, encryptType);
//        signature = MD5Utils.encrypt(userName + ":" + realm + ":" + signature, encryptType);
//        signature = MD5Utils.encrypt(signature + ":" + randomKey, encryptType);
//        return signature;
//    }

    private static String md5Encrypt(String str){

        char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
        try {
            byte[] btInput = str.getBytes();
            MessageDigest mdInst = MessageDigest.getInstance("md5");
            mdInst.update(btInput);
            byte[] md = mdInst.digest();
            int j = md.length;
            char[] chars = new char[j * 2];
            int k = 0;
            for (byte byte0 : md) {
                chars[k++] = hexDigits[byte0 >>> 4 & 0xf];
                chars[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(chars);
        } catch (Exception e) {
            return null;
        }




    }

    public static void main(String[] args) throws Exception {
        System.out.println(md5Encrypt("123abc"));
        MessageDigest instance = MessageDigest.getInstance("md5");
        byte[] digest = instance.digest("123abc".getBytes());
        System.out.println();
        MD5 md5 = MD5.create();
        System.out.println(md5.digestHex("123abc"));
    }
}

